package xyz.gzdxc.common.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xyz.gzdxc.common.mysql.repository.UserTokenRepository;
import xyz.gzdxc.common.service.UserPrivService;

import java.util.List;

@Service
public class UserPrivServiceImpl implements UserPrivService {

    @Autowired
    UserTokenRepository userTokenRepository;

    @Override
    public boolean hasPriv(Long userId, String privCode) {
        //todo judge whether the user has the priv
        if(privCode == null){
            return false;
        }
        boolean hasPriv = false;
        List<String> privList = getPrivListByUserId(userId);
        if(privList != null && privList.size() > 0){
            for (String priv: privList) {
                if(privCode.equals(priv)){
                    hasPriv = true;
                }
            }
        }
        return hasPriv;
    }

    @Override
    public List<String> getPrivListByUserId(Long userId) {
        return userTokenRepository.getPrivListByUserId(userId);
    }
}
